package com.woniuxy.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: mayuhang  <br/>
 * Date: 2021/3/25:15:03  <br/>
 * Description:用于测试备用交换机的普通topic交换机配置
 */
@Configuration
public class TestAlterExchangeConfig {
    @Bean
    public TopicExchange normalExchange(){
        //设置备用交换机配置
        Map<String, Object> pros = new HashMap<>();
        //设置交"alternate-exchange"属性数据 如果路由失败，即发送到备用交换机处理
        pros.put("alternate-exchange", AlternateExchangeConfig.ALTERNAME_EXCHANGE);
        TopicExchange topicExchange=new TopicExchange("normalExchange",true,false,pros);
        return topicExchange;
    }

    @Bean
    public Queue normalQueue() {
        Queue queue=new Queue("normalqueue");
        return queue;
    }

    //binding将交换机和相应队列连起来
    @Bean
    public Binding bindingNormalQueue(){
        Binding binding= BindingBuilder.bind(normalQueue()).to(normalExchange()).with("normalkey");
        return binding;
    }
}
